package com.diver.flinkdemo.utils;


import com.diver.flinkdemo.config.PropsConfig;

import javax.annotation.PostConstruct;

//@Component
public class PropertyUtil {
//    @Autowired
    private PropsConfig propsConfig;

    //在静态方法中注入config类:建立一个当前类的静态属性
    private static PropertyUtil propertyUtil;

    //使用PostConstruct，注解init方法，在方法中为当前类静态属性赋值
    @PostConstruct
    private void init() {
        propertyUtil = this;
        propertyUtil.propsConfig = this.propsConfig;
    }

    public static String readValue(String key) {
        if (key.equals("privateKey")) {
            return propertyUtil.propsConfig.getPrivateKey();
        } else if (key.equals("publicKey")) {
            return propertyUtil.propsConfig.getPublicKey();
        } else if (key.equals("appID")) {
            return propertyUtil.propsConfig.getAppID();
        } else if (key.equals("appsecret")) {
            return propertyUtil.propsConfig.getAppsecret();
        } else if (key.equals("tokenManager")) {
            return propertyUtil.propsConfig.getTokenManager();
        } else if (key.equals("appIDErrandDog")) {
            return propertyUtil.propsConfig.getAppIDErrandDog();
        } else if (key.equals("appsecretErrandDog")) {
            return propertyUtil.propsConfig.getAppsecretErrandDog();
        } else if (key.equals("appIDGbg")) {
            return propertyUtil.propsConfig.getAppIDGbg();
        } else if (key.equals("appsecretGbg")) {
            return propertyUtil.propsConfig.getAppsecretGbg();
        } else if (key.equals("appIDWalrus")) {
            return propertyUtil.propsConfig.getAppIDWalrus();
        } else if (key.equals("appSecretWalrus")) {
            return propertyUtil.propsConfig.getAppSecretWalrus();
        } else if (key.equals("wReturnPrefix")) {
            return propertyUtil.propsConfig.getWReturnPrefix();
        } else if (key.equals("wReturnUrl")) {
            return propertyUtil.propsConfig.getWReturnUrl();
        }
        return null;
    }

    public static void writeValue(String key, String value) {
        if (key.equals("privateKey")) {
            propertyUtil.propsConfig.setPrivateKey(value);
        } else if (key.equals("publicKey")) {
            propertyUtil.propsConfig.setPublicKey(value);
        }
    }
}
